/*
 *  SpaceShip.cpp
 *  GLRender
 *
 *  Created by Patrick zulian on 5/4/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#include "SpaceShip.h"
#include "Physics.h"
#include "SoundEngine.h"
#include "Player.h"
#include "Bonus.h"

SpaceShip::SpaceShip(Player *p, const Point3d &position, Point3d &velocity0, const double _mass):
WMovingObject(position, velocity0, _mass, 2) 
{
	this->p = p;
	setLife(this->getMaxLife());
	setStrength(0.5);
        reaction.addReaction("SpaceShip", IGNORED);
        reaction.addReaction("Projectile", IGNORED);
	      reaction.addReaction("Asteroid",HARM);
}


void SpaceShip::renderOn(AbstractRenderer *renderer){ Q_UNUSED(renderer);}

void SpaceShip::onCollision (WObject *from)
{

	switch (from->getReaction().getReaction("SpaceShip")) {
		case DIE:
      {
			//Physics::getInstance()->collide(this, from);
			//WMovingObject::collided = true;
			this->alive() = false;
			break;
      }
    case HARM:
      {

      

      this->life -= from->getStrength();
			if (this->life <= 0) {
				this->alive() = false;
				SoundEngine::getInstance()->play("Explosion");
			} else {
				SoundEngine::getInstance()->play("Impact");

			}

			break;
      }
    default:
			break;
	}
}

void 
SpaceShip::applyBonus (Bonus *b)
{
	b->applyBonus(p);
}
